<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use app\common\model\Files as fileModel;
use think\facade\View;


class Appendix extends AdminController {

    public function index(){

        if($this->request->isAjax()){
            $model = new fileModel();
            $re['code'] = 0;
            $re['msg'] = '';
            $re['data'] = [];
            $re['count'] = 0;
            $res = $model->order('id','desc')->where('file_type','appendix_copy')->paginate()->toArray();
            if(sizeof($res['data'])>0){
                $re['data'] = $res['data'];
                $re['count'] = $res['total'];
            }
            return $re;
        }else{
            return View::fetch();

        }

    }


    public function del(){

        $result = [
            'status' => false,
            'msg' => error_code(10037,true),
            'data' => ''
        ];
        $id = $this->request->param('id');
        $model = new fileModel();
        $res = $model->where('id',$id)->delete();
        if($res) {
            $this->setActionLog('删除附件',$this->admin_info['name'].'：删除附件'.$id);
            $result['status'] = true;
            $result['msg'] = '删除成功';
        }else{
            $result['msg'] = '删除失败，请联系管理员';
        }
        return $result;
    }
}
